﻿
var Cb_linkCss = "http://analytics.cybermedia.vn/AdvBanner/Coke-Nio/AdCyber_Coke2012.css";
var Cb_pathFlashSmall = "http://analytics.cybermedia.vn/AdvBanner/Coke-Nio/Coke_280x230_TCBD.swf";

var Cb_loopMax = 3; // mỗi máy client chạy 3 lần
var Cb_cookieName = 'Coke2012_TapChiBongDa'; // đặt tên cho cookie
var Cb_cookieTimeOut = 30; // 30 phút

function CreateDiv() {

    var Cb_myCoo = getCookie(Cb_cookieName);
    if (Cb_myCoo < Cb_loopMax) // số lần nhỏ hơn quy định, được phép chạy
    {
        if (Cb_myCoo == 0) {
            eraseCookie(Cb_cookieName); // xóa hết
            setCookie(Cb_cookieName, '1', Cb_cookieTimeOut); // khởi tạo 1 lần, timeout 30 phút
        }
        else {
            eraseCookie(Cb_cookieName); // xóa hết
            var Cb_myCooNew = parseInt(Cb_myCoo) + 1; // tăng số lần lên 1
            setCookie(Cb_cookieName, Cb_myCooNew, Cb_cookieTimeOut); // timeout 30 phút
        }

        var _body = document.getElementsByTagName('body')[0];
        var _linkCss = document.createElement('link');

        _linkCss.setAttribute('href', Cb_linkCss);
        _linkCss.setAttribute('rel', 'stylesheet');
        _linkCss.setAttribute('type', 'text/css');
        _body.appendChild(_linkCss);

        var _divAdMini = document.createElement('div');
        _divAdMini.id = "divAdMini";
        _divAdMini.align = "center";
        _body.appendChild(_divAdMini);

        CreateDivMini();
    }
}
//window.onload = CreateDiv;
$(document).ready(function () {
    CreateDiv();
});

function Close() {
    document.getElementById("divAdMini").style.display = 'none';
}
function CreateDivMini() {
    var bannerMini = "<object width=\"280\" height=\"230\" border=\"0\" align=\"middle\"";
    bannerMini += " codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\" ";
    bannerMini += " classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\">";
    bannerMini += "<param value=\"" + Cb_pathFlashSmall + "\" name=\"movie\">";
    bannerMini += "<param value=\"always\" name=\"AllowScriptAccess\">";
    bannerMini += "<param value=\"High\" name=\"quality\">";
    bannerMini += "<param value=\"transparent\" name=\"wmode\">";
    bannerMini += "<param value=\"link=\" name=\"FlashVars\">";
    bannerMini += " <embed width=\"280\" height=\"230\" allowscriptaccess=\"always\" wmode=\"transparent\"";
    bannerMini += " type=\"application/x-shockwave-flash\" ";
    bannerMini += " pluginspage=\"http://www.macromedia.com/go/getflashplayer\"";
    bannerMini += " flashvars=\"link=\" src=\"" + Cb_pathFlashSmall + "\">";
    bannerMini += "</object>";
    var divEmbed = document.getElementById("divAdMini");
    divEmbed.innerHTML = bannerMini;
}

// thiết lập cookie
function setCookie(name, value, minute) {
    if (minute) {
        var date = new Date();
        date.setTime(date.getTime() + (minute * 60 * 1000));
        // date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

// Lấy cookie theo tên
function getCookie(c_name) {
    var ARRcookies = document.cookie.split(";");
    var j = ARRcookies.length;

    for (var i = 0; i < j; i++) {
        if (ARRcookies[i] != null) {
            var x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("=", 0)).replace(/^\s+|\s+$/g, '');
            var y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);

            if (x == c_name) {
                return unescape(y);
            }
        }
    }
    return 0;
}

// xóa cookie theo tên
function eraseCookie(name) {
    setCookie(name, "", -1);
}

/// Xóa toàn bộ Cookie
function deleteAllCookies() {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}